﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace GDI
{
    public partial class TransparentPanel : Panel
    {
        private int f_Alpha = 0;

        public int Alpha { get { return f_Alpha; } set { f_Alpha = value; Invalidate(); } }

        protected override CreateParams CreateParams
        {
            get
            {
                const int WS_EX_TRANSPARENT = 0x00000020;
                CreateParams createParams = base.CreateParams;
                createParams.ExStyle |= WS_EX_TRANSPARENT;
                return createParams;
            }
        }

        public TransparentPanel()
        {
            SetStyle(ControlStyles.Opaque, true);
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(f_Alpha, BackColor)), 0, 0, Width, Height);
            base.OnPaint(e);
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, BackColor)), 0, 0, Width, Height);
            //base.OnPaintBackground(e);
        }

        protected override void OnMove(EventArgs e)
        {
            if(Parent != null)
                Parent.Invalidate(Bounds, true);
        }
    }
}
